#include<iostream>
#include<vector>
#include<stack>
using namespace std;

bool check(vector<int>& pushV, vector<int>& popV)
{
    if(pushV.size() != popV.size()) return false;
    stack<int> s;
    int left = 0;
    for(int i = 0; i < pushV.size(); i++)
    {
        s.push(pushV[i]);
        while(!s.empty() && s.top() == popV[left++]) s.pop();
    }
    return s.empty();
}
int main()
{
    int n = 0;
    cin >> n;
    vector<int> pushV(n);
    vector<int> popV(n);
    
    for(int i = 0; i < n; i++) cin >> pushV[i];
    for(int i = 0; i < n; i++) cin >> popV[i];
    
    if(check(pushV, popV)) cout << "true" << endl;
    else cout << "false" << endl;
    return 0;
}
